package com.ll.menu.user.app.http;


import com.ll.menu.user.app.http.retrofit.RetrofitFactory;
import com.ll.menu.user.app.http.service.MainService;
import com.ll.menu.user.app.user.UserManager;

/**
 * 接口工厂
 *
 * @author wangheng
 */
public final class ServiceFactory {

    private static String sToken = null;

    private static MainService sMainService;

    public static void recycle() {
        sMainService = null;
        sToken = null;
    }

    public static MainService getMainService() {
        if (!needCreateService(sMainService)) {
            return sMainService;
        }
        sToken = UserManager.getInstance().getToken();
        sMainService = RetrofitFactory.createApiRetrofit(sToken).create(MainService.class);
        return sMainService;
    }

    private static boolean needCreateService(Object service) {

        if (service == null || sToken == null) {
            return true;
        }
        String token = UserManager.getInstance().getToken();

        return !sToken.equals(token);

    }

}
